package org.clockworkmages.games.anno1186.situations.gameoptions;

import java.io.File;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.clockworkmages.games.anno1186.SaveFilenameFilter;
import org.clockworkmages.games.anno1186.gui.GameUiUtil;
import org.clockworkmages.games.anno1186.model.option.GoBackOption;
import org.clockworkmages.games.anno1186.model.option.Option;
import org.clockworkmages.games.anno1186.model.situation.Situation;
import org.clockworkmages.games.anno1186.situations.gameoptions.options.SelectLoadSlotOption;

public class LoadGameSituation
		extends Situation {

	@Override
	public void update() {
		super.update();

		List<Option> options = getOptions();
		options.clear();

		try {
			File gameDataDirectory = new File(".");

			Set<String> existingSaveFiles = new HashSet<String>();
			File[] saveFiles = gameDataDirectory
					.listFiles(new SaveFilenameFilter());
			int index = 1;
			for (File saveFile : saveFiles) {
				options.add(new SelectLoadSlotOption(index++, saveFile
						.getName()));
			}

		} catch (Exception e) {
			GameUiUtil.logError(e);
			throw new RuntimeException(e);
		}

		options.add(GoBackOption.INSTANCE);
	}
}